package inline;

import android.content.Context;
import android.text.TextUtils;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.share.interf.IShareArticleBean;
import com.ss.android.article.common.share.interf.ISharePostBean;
import com.ss.android.article.share.d.e;
import com.ss.android.article.share.entity.ShareAction;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.image.Image;

import java.util.List;

public class ShareDemo {
    public static boolean a(Context arg9, long arg10, String arg12, IShareArticleBean arg13, boolean arg14) {
        String v0_2;
        boolean v0;
        if (!arg14) {
            v0 = false;
            return v0;
        }

        if (arg13 == null || arg13.getGroupId() != arg10) {
            v0 = false;
        } else if (android.support.design.a.isTextEmpty(arg12)) {
            UIUtils.showImageToast(arg9, R.drawable.close_popup_textpage, R.string.a0q);
            v0 = false;
        } else {
            MobClickCombiner.onEvent(arg9, "xiangping", "system_share_content");
            String v2 = "-----------------------------";
            try {
                arg12 = arg12.replaceFirst("\\s*<div\\s+id=\"toggle_img\"\\s*>\\s*<a(\\s+[a-zA-Z_]+=\"[^\"]*\")*\\s*>[^<>]*</a>\\s*</div>\\s*", "").replaceFirst("<span\\s+class=\"time\"\\s*>[^<>]+</span>", "$0 <br/>" + v2 + "<br/>").replaceFirst("<div\\s+class=\"title\"\\s*>([^<>]+)</div>", "<b>$1</b><br/>").replaceAll("<a\\s+class=\"image\"\\s+href=\"bytedance://large_image[^\"]+\"\\s+origin_src=\"([^\"]+)\"\\s+thumb_src=\"[^\"]+\"(\\s+[a-zA-Z_]+=\"[^\"]*\")*\\s*>\\s*<span\\s+class=\"i-holder\"></span>\\s*<span\\s+class=\"t-holder\"\\s*>[^<>]*</span>", "<img src=\"$1\" /> $1 ").replaceFirst("<div\\s*id=\"src\">\\s*<a\\s*href=\"([^\"]+)\"\\s*>([^<>]+)</a>\\s*</div>", " ");
                v0_2 = arg12.replaceAll("<style>[^<>]+</style>", " ");
            } catch (Exception v0_1) {
                v0_2 = arg12;
            }

            String v3 = arg9.getString(com.ss.android.article.browser.R.string.dr);
            String v4 = arg9.getString(com.ss.android.article.browser.R.string.app_name);
            StringBuilder v5 = new StringBuilder();
            v5.append("<p>(").append(arg9.getString(com.ss.android.article.browser.R.string.html_share_text));
            v5.append(" <a href=\"").append(v3).append("\">");
            v5.append(v4).append("</a> ");
            v5.append(v3).append(")</p>");
            v5.append(v0_2);
            if (!android.support.design.a.isTextEmpty(arg13.getShareUrl())) {
                v5.append("<br/><a href=\"").append(arg13.getShareUrl()).append("\">");
                v5.append(arg9.getString(com.ss.android.article.browser.R.string.html_share_view_src)).append("</a> ").append(arg13.getShareUrl());
                v0_2 = String.format(arg9.getString(com.ss.android.article.browser.R.string.html_share_view_comment), Integer.valueOf(arg13.D()));
                v5.append("<br/><a href=\"").append(arg13.getShareUrl()).append("\">");
                v5.append(v0_2).append("</a> ").append(arg13.getShareUrl());
            }

            v5.append("<p> </p>" + v2 + "<br/>");
            v5.append(arg9.getString(com.ss.android.article.browser.R.string.html_share_slogan));
            v5.append("<p>").append(arg9.getString(com.ss.android.article.browser.R.string.html_share_desc)).append("</p>");
            v5.append("<p>").append(arg9.getString(com.ss.android.article.browser.R.string.html_share_download));
            v5.append(" <a href=\"").append(v3).append("\">").append(v4).append("</a> ");
            v5.append(v3).append("</p>");
            v0 = new e(arg9).a(ShareAction.text).b(v5.toString()).a(String.format(arg9.getString(com.ss.android.article.browser.R.string.vf), arg13.getTitle())).a();
        }

        return v0;
    }

    public static String a(Context arg2, ISharePostBean arg3) {
        if (arg3.c() != null) {
            arg3 = arg3.c();
        }

        String v0 = arg3.h();
        if (android.support.design.a.isTextEmpty(v0)) {
            v0 = arg2.getString(com.ss.android.article.browser.R.string.app_name);
        }

        return v0;
    }

    public static String a(ISharePostBean arg4) {
        String v0;
        if (arg4.c() != null) {
            arg4 = arg4.c();
        }

        if (arg4.b() > 0f) {
            v0 = arg4.a();
            if (android.support.design.a.isTextEmpty(v0)) {
                v0 = arg4.i();
            }

            v0 = "评分：" + arg4.b() * 2f + "分，" + v0;
        } else {
            StringBuilder v0_1 = new StringBuilder();
            if (!TextUtils.isEmpty(arg4.k())) {
                v0_1.append(arg4.k());
                v0_1.append("：");
            }

            if (!android.support.design.a.isTextEmpty(arg4.i())) {
                v0_1.append("「");
                v0_1.append(arg4.i());
                v0_1.append("」");
            }

            v0_1.append(arg4.a());
            v0 = v0_1.toString();
        }

        return v0;
    }

    public static String b(ISharePostBean arg4) {
        if (arg4.c() != null) {
            arg4 = arg4.c();
        }

        String v0 = "";
        String v1 = arg4.b() <= 0f || arg4.g() == null ? v0 : arg4.g();
        if ((android.support.design.a.isTextEmpty(v1)) && arg4.d() != null && arg4.d().size() > 0) {
            List<Image.UrlItem> v0_1 = ((Image) arg4.d().get(0)).url_list;
            if (v0_1 != null && v0_1.size() > 0) {
                v1 = v0_1.get(0).url;
            }
        }

        if ((android.support.design.a.isTextEmpty(v1)) && arg4.f() != null) {
            v1 = arg4.f();
        }

        if ((android.support.design.a.isTextEmpty(v1)) && arg4.g() != null) {
            v1 = arg4.g();
        }

        if (!android.support.design.a.isTextEmpty(v1)) {
            v0 = v1;
        } else if (!TextUtils.isEmpty(arg4.e())) {
            v0 = arg4.e();
        } else {
            v0 = "";
        }

        return v0;
    }

    public static String a(String arg3, String arg4, String arg5) {
        String v0_1;
        if ((android.support.design.a.isTextEmpty(arg3)) || (android.support.design.a.isTextEmpty(arg3)) || (android.support.design.a.isTextEmpty(arg3))) {
            v0_1 = "";
        } else {
            UrlBuilder v0 = new UrlBuilder(arg3);
            if (!android.support.design.a.isTextEmpty(arg4)) {
                if (("weixin".equals(arg4)) || ("weixin_moments".equals(arg4))) {
                    v0.addParam("wxshare_count", 1);
                }

                v0.addParam("tt_from", arg4);
            }

            if (!android.support.design.a.isTextEmpty(arg5)) {
                v0.addParam("utm_source", arg5);
            }

            v0.addParam("utm_medium", "toutiao_android");
            v0.addParam("utm_campaign", "client_share");
            v0_1 = v0.build();
        }

        return v0_1;
    }
}
